package com.chenglai.goods.service;

import com.chenglai.goods.dao.GoodsParamMapper;
import com.chenglai.goods.pojo.GoodsParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;

/**
 * 类描述：
 *
 * @Author rxh
 * @Date 2023/11/17 9:32
 */
@Service
public class GoodsParamServiceImpl implements GoodsParamService {

    @Resource
    private GoodsParamMapper goodsParamMapper;

    @Override
    public PageInfo getGoodsParamList(Integer page, Integer size, Integer shopId) {
        PageHelper.startPage(page, size);
        Example example = new Example(GoodsParam.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("shopId", shopId);
        example.orderBy("paramId").desc();
        return new PageInfo(goodsParamMapper.selectByExample(example));
    }

    @Override
    public void editGoodsParam(GoodsParam goodsParam) {
        if (goodsParam.getParamId() == null) {
            //添加
            goodsParamMapper.insertSelective(goodsParam);
        } else {
            //修改
            goodsParamMapper.updateByPrimaryKeySelective(goodsParam);
        }
    }

    @Override
    public void delGoodsParam(Integer paramId) {
        goodsParamMapper.deleteByPrimaryKey(paramId);
    }

    @Override
    public GoodsParam detail(Integer paramId) {
        return goodsParamMapper.selectByPrimaryKey(paramId);
    }
}
